<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
	<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>-SGBD Aluno</title>
<script src="<c:url value="/root/js/jquery.js"/>"></script>
<script type="text/javascript">
	$(document).ready(function(){
		iniciar();
		<c:if test="${msg != null}">
			alert("${msg}");
		</c:if>
	
	});	
	
	function iniciar(){
		<c:if test="${aluno != null}">
			$("#id").val("${aluno.id}");
			$("#nome").val("${aluno.nome}");
			$("#idade").val("${aluno.idade}");
			$("#btnPersistir").val("Alterar");
			$("#pgTitulo").val("Alterando Aluno");
		</c:if>
	}
	
	function salvar(){
		if($("#nome").val() == ""){
			alert("Informe o nome!");
		}else if($("#idade").val() == ""){
			alert("Informe a idade!");
		}else{
			$("#formA").submit();
		}
	}
	
</script>
</head>
<body>
	
	<h1 id="pgTitulo">Cadastrando Aluno</h1>
	<form id="formA" action="persistir" method="post">
		<input type="hidden" id="id" name="id" value="0" />
		<ul>
			<li><label>Nome: <input id="nome" name="nome" type="text"  /></label></li>
			<li><label>Idade: <input size="3" maxlength="3" id="idade" name="idade" type="text"  /></label></li>
			<li><input type="button" id="btnPersistir" value="Adicionar" onclick="salvar()" /></li>
		</ul>
	</form>
</body>
</html>